const path = require('path')
const htmlWebpackPlugin = require('html-webpack-plugin')
// 导入每次删除dist目录插件
const { CleanWebpackPlugin } = require('clean-webpack-plugin')


module.exports  = {
  entry: path.join(__dirname, './src/main.js'),
  output: {
    path: path.join(__dirname, "./dist"),
    filename: 'bundle.js'
  },
  plugins: [
    new htmlWebpackPlugin({
      template: path.join(__dirname, './src/index.html'),
      filename: 'index.html'
    }),
    new CleanWebpackPlugin()
  ],
  module: {
    rules: [
      // 次数为css-loader传递得参数是为了实现css的模块化
      {test: /\.css$/, use: ['style-loader', 'css-loader']}, 
      {test: /\.scss$/, use: ['style-loader', 'css-loader?modules','sass-loader']},
      {test: /\.(png|jpg|jpeg|bmp|gif)$/, use: ['url-loader?limit=5000']},
      {test: /\.jsx?$/, use: 'babel-loader', exclude: /node_modules/ }
    ]
  },
  //解决解析jsx文件问题
  resolve: {
    extensions: ['.js', '.jsx'], //后缀名自动补全
  }
} 